/**
 * 获取当前运行的客户端(APP H5 小程序)
 * https://uniapp.dcloud.io/platform
 */
import store from '@/store';
const getPlatform = () => {
	let systemInfo = uni.getSystemInfoSync()
	if ((systemInfo.platform.toLowerCase().indexOf('win') == 0) || (systemInfo.platform
			.toLowerCase().indexOf('mac') == 0) || (systemInfo.platform.toLowerCase()
			.indexOf('linux') == 0)) {
		systemInfo.isPC = true
	}
	if (systemInfo.system.toLowerCase().indexOf('ios') > -1) {
		systemInfo.system = 'ios';
	} else {
		systemInfo.system = 'android';
	}
	
  // #ifdef MP-WEIXIN
		const platform = {
			type:'MP-WEIXIN',
			sourceSign:'微信小程序',
			platform:3, // 绑定手机号平台类型
			device: systemInfo.isPC ? 1 : systemInfo.system == 'android' ? 2 : 3,// 1PC  2安卓  3IOS
			sourceType: 2, // 线上自营
			dfs: 'wexin.mp.toc',
			appPayType: 5, // 支付类型
			payDeviceType: 6 // 支付设备
		}
  // #endif
	
  return platform
}

// 是否为微信公众号端
const weixinOfficial = () => {
  // #ifdef H5
  const ua = window.navigator.userAgent.toLowerCase()
  return String(ua.match(/MicroMessenger/i)) === 'micromessenger'
  // #endif
  return false
}

const platfrom = getPlatform()

export const isH5 = platfrom.type === 'H5'
export const isApp = platfrom.type === 'APP'
export const isMpWeixin = platfrom.type === 'MP-WEIXIN'

// 是否为微信公众号端
// 相当于H5端运行在微信内置浏览器, 但是需要使用微信的jssdk所以要单独区分
export const isWeixinOfficial = platfrom.type === 'H5-WEIXIN'

export default platfrom
